<script setup>
import { onMounted, ref, computed } from 'vue'
import { useRoute } from 'vue-router'
import { reqHotGoodsAPI } from '@/api/order'
import GoodsIndex from "@/components/goods/GoodsIndex.vue";

// 接收父组件传递的 hotType
const props = defineProps({
  hotType: {
    type: Number,
  }
})
// 适配title，根据hotType来显示不同标题  1：24小时热榜 ， 2：周热榜
const TYPEMAP = {
  1: '24小时热榜',
  2: '周热榜'
}
const title = computed(() => {
  return TYPEMAP[props.hotType]
})

// 1. 封装接口
// 2. 调用接口渲染模版
onMounted(() => getHotGooddsList())
const hotGoodsList = ref([])
const route = useRoute()
const getHotGooddsList = async () => {
  const res = await reqHotGoodsAPI({
    type: props.hotType,
    id: route.params.id
  })
  hotGoodsList.value = res.data.result
}


</script>

<template>
  <div class="detail-hot">
    <h3>{{ title }}</h3>
    <!-- 商品区块 -->
    <ul>
      <li v-for="goods in hotGoodsList" :key="goods.id">
        <GoodsIndex :goods="goods"/>
      </li>
    </ul>
  </div>
</template>

<style scoped lang="scss">
.detail-hot {
  h3 {
    height: 70px;
    line-height: 70px;
    text-align: center;
    font-size: 20px;
    background-color: #f60;
    color: #fff;
    margin-bottom: 10px;
  }

}

</style>